<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
        <link rel="stylesheet" href="/css/font.css">
        <link rel="stylesheet" href="/css/xadmin.css">
        <script src="/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">
                {php}echo config('name.home_tab'){/php}
            </a>
            <a href="">
                {php}echo config('name.admin_tab'){/php}
            </a>
            <a>
                <cite>
                    {php}echo config('name.admin_list_tab'){/php}
                </cite>
            </a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body "></div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('{php}echo config('name.add_admin_button'){/php}','/adminAdd',600,340)">
                                <i class="layui-icon"></i>
                                {php}echo config('name.add_button'){/php}
                            </button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th>
                                      {php}echo config('name.id'){/php}
                                  </th>
                                  <th>
                                      {php}echo config('name.account'){/php}
                                  </th>
                                  <th>
                                      {php}echo config('name.role'){/php}
                                  </th>
                                  <th>
                                      {php}echo config('name.date'){/php}
                                  </th>
                                  <th>
                                      {php}echo config('name.state'){/php}
                                  </th>
                                  <th>
                                      {php}echo config('name.operating'){/php}
                                  </th>
                              </thead>
                              <tbody>
                              {php}$adminUsers = \app\controller\AdminUsers::read(new \app\model\AdminUsers());{/php}
                              {foreach $adminUsers as $v}
                                <tr>
                                  <td>{$v.id}</td>
                                  <td>{$v.account}</td>
                                  <td>
                                      {php}$adminRoles = \app\controller\AdminUsersRole::getUsersRole(new \app\model\AdminUsersRole(), $v['id']);{/php}
                                      {foreach $adminRoles as $rolesValue}
                                          {foreach $rolesValue['role_list'] as $roleListValue}
                                          {$roleListValue.role_name}
                                          {/foreach}
                                      {/foreach}
                                  </td>
                                  <td>{$v.create_time}</td>
                                  <td class="td-status">
                                      {switch $v['disable_state'] }
                                      {case 0}
                                        <span class="layui-btn layui-btn-mini">
                                            {php}echo config('name.open'){/php}
                                        </span>
                                      {/case}
                                      {default /}
                                        <span class="layui-btn layui-btn-disabled layui-btn-mini">
                                            {php}echo config('name.stop'){/php}
                                        </span>
                                      {/switch}
                                  </td>
                                  <td class="td-manage">
                                      {switch $v['disable_state'] }
                                      {case 0}
                                        <a onclick="member_stop(this,'{$v.id}')" href="javascript:;"  title="{php}echo config('name.stop'){/php}">
                                          <i class="layui-icon">&#xe62f;</i>
                                        </a>
                                      {/case}
                                      {default /}
                                          <a onclick="member_stop(this,'{$v.id}')" href="javascript:;"  title="{php}echo config('name.open'){/php}">
                                              <i class="layui-icon">&#xe601;</i>
                                          </a>
                                      {/switch}
                                    <a title="{php}echo config('name.edit'){/php}"  onclick="xadmin.open('{php}echo config('name.edit'){/php}','/adminEdit/{$v.id}',600,340)" href="javascript:;">
                                      <i class="layui-icon">&#xe642;</i>
                                    </a>
                                    <a title="{php}echo config('name.delete'){/php}" onclick="member_del(this,'{$v.id}')" href="javascript:;">
                                      <i class="layui-icon">&#xe640;</i>
                                    </a>
                                  </td>
                                </tr>
                              {/foreach}
                              </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要执行此操作吗？',function(index){
              if($(obj).attr('title')=='启用'){
                  $.ajax({
                      type: "POST",
                      url: "/unDisableAdminUser",
                      data: {
                          id:id
                      },
                      dataType: "json",
                      success: function(data){
                          switch(data) {
                              case 200:
                                  $(obj).attr('title','停用');
                                  $(obj).find('i').html('&#xe62f;');
                                  $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('启用');
                                  layer.msg('已启用!');
                                  break;
                              default:
                                  layer.msg('未知错误！');
                          }
                      }
                  });
              }else{
                  $.ajax({
                      type: "POST",
                      url: "/disableAdminUser",
                      data: {
                          id:id
                      },
                      dataType: "json",
                      success: function(data){
                          switch(data) {
                              case 200:
                                  $(obj).attr('title','启用');
                                  $(obj).find('i').html('&#xe601;');
                                  $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('禁用');
                                  layer.msg('已禁用!');
                                  break;
                              default:
                                  layer.msg('未知错误！');
                          }
                      }
                  });
              }
          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              $.ajax({
                  type: "POST",
                  url: "/deleteAdminUser",
                  data: {
                      id:id
                  },
                  dataType: "json",
                  success: function(data){
                      switch(data) {
                          case 200:
                              $(obj).parents("tr").remove();
                              layer.msg('已删除!',{icon:1,time:1000});
                              break;
                          default:
                              layer.msg('未知错误！');
                      }
                  }
              });
          });
      }
    </script>
</html>